package com.mars.module.oss.controller;

import com.mars.common.result.R;
import com.mars.module.admin.entity.MinioUtils;
import com.mars.module.oss.service.IFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.util.UUID;

/**
 * @author 程序员Mars
 */
@Api(tags = "图片上传接口")
@RestController
@RequestMapping("/common/upload")
public class FileController {

    @Resource
    private IFileService fileService;

    /**
     * 图片上传
     *
     * @param file file
     * @return R
     */
    @ApiOperation(value = "图片上传")
    @CrossOrigin
    @PostMapping(value = "/file")
    public R<String> upload(@RequestParam(value = "file") MultipartFile file) throws Exception {
        MinioUtils minioUtils = new MinioUtils();
        String url = minioUtils.upload(file); //将图片上传到Minio中
        return R.success(url);
    }
}
